<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>let-const块级作用域应用</title>
</head>
<body>

  <button>按钮0</button>
  <button>按钮1</button>
  <button>按钮2</button>
  <button>按钮3</button>

  <script>
    const buttonEl =  document.querySelectorAll("button")
    for (let i = 0; i < buttonEl.length; i++) {
      
      buttonEl[i].onclick = function() {
        console.log(`点击了按钮${i}`)
      }
    }
  </script>
</body>
</html>